#https://www.cnblogs.com/ellisonzhang/p/10430118.html


from socketserver import BaseRequestHandler, TCPServer
class RequestHandler(BaseRequestHandler):
 # override base class handle method
    def handle(self):
        print('Server connected to: ', self.client_address)
        # rsp = self.request.recv(512)
        # self.request.send(b'Server received: ' + rsp)
        while True:
            rsp = self.request.recv(512)
            if not rsp: break
            self.request.send(b'Server received: ' + rsp)
def startServer():
    serv = TCPServer(('', 24000), RequestHandler)
    serv.serve_forever()
startServer()